package com.seedwill.common.persistence;

import com.seedwill.common.meta.core.XEnumOperator;
import com.seedwill.xul.core.XSchemaFilter;

/**
 * 简化的过滤器
 * 
 * @author kdyi
 *
 */
public class Filter implements java.io.Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2362549179366232958L;

	public static final XEnumOperator DEFAULT_OPERATOR = XEnumOperator.EQ;

	private Object defaultOperTargetValue;
	
	public Filter(String operTarget, Object operTargetValue) {
		super();
		this.caseSensitive = false;
		this.operator = DEFAULT_OPERATOR;
		this.operTarget = operTarget;
		this.operTargetValue = operTargetValue;
	}

	public Filter(XEnumOperator operator, String operTarget,
			Object operTargetValue) {
		super();
		this.caseSensitive = false;
		this.operator = operator;
		this.operTarget = operTarget;
		this.operTargetValue = operTargetValue;
	}

	public Filter(XEnumOperator operator, String operTarget,
			Object operTargetValue, boolean caseSensitive) {
		super();
		this.operator = operator;
		this.operTarget = operTarget;
		this.operTargetValue = operTargetValue;
		this.caseSensitive = caseSensitive;
	}
	public Filter(XEnumOperator operator, String operTarget, boolean caseSensitive) {
		super();
		this.operator = operator;
		this.operTarget = operTarget;
		this.caseSensitive = caseSensitive;
	}
	public XEnumOperator getOperator() {
		return operator;
	}

	public void setOperator(XEnumOperator operator) {
		this.operator = operator;
	}

	public String getOperTarget() {
		return operTarget;
	}

	public void setOperTarget(String operTarget) {
		this.operTarget = operTarget;
	}

	public Object getOperTargetValue() {
		return operTargetValue;
	}

	public void setOperTargetValue(Object operTargetValue) {
		this.operTargetValue = operTargetValue;
	}

	/**
	 * 操作符
	 */
	private XEnumOperator operator;
	
	/**
	 * 操作属性名称
	 */
	private String operTarget;
	
	/**
	 * 操作属性值
	 */
	private Object operTargetValue;
	
	/**
	 * 大小写敏感
	 */
	private boolean caseSensitive;
	
	public boolean isCaseSensitive() {
		return caseSensitive;
	}

	public void setCaseSensitive(boolean caseSensitive) {
		this.caseSensitive = caseSensitive;
	}

	/**
	 * 是否条件语句
	 * @return
	 */
	public boolean isClause(){
		return operator!=null && operator.compareTo(XEnumOperator.CLAUSE)==0;
	}
	
	public static Filter newInstanceBy(XSchemaFilter schemaFilter){
		return new Filter(XEnumOperator.valueOf(schemaFilter.getOperator().toUpperCase()), schemaFilter.getTarget(), schemaFilter.getExpresionArray(), schemaFilter.getCaseSensitive());
	}
	
	public static Filter newInstance(String operTarget, Object operTargetValue){
		return new Filter(operTarget, operTargetValue);
	}
	public static Filter newInstance(XEnumOperator operator, String operTarget, Object operTargetValue){
		return new Filter(operator, operTarget, operTargetValue);
	}
	public static Filter newInstance(XEnumOperator operator, String operTarget, Object operTargetValue, boolean caseSensitive){
		return new Filter(operator, operTarget, operTargetValue, caseSensitive);
	}
	public static Filter newInstance(XEnumOperator operator, String operTarget, boolean caseSensitive){
		return new Filter(operator, operTarget, caseSensitive);
	}
	public Object getDefaultOperTargetValue() {
		return defaultOperTargetValue;
	}

	public void setDefaultOperTargetValue(Object defaultOperTargetValue) {
		this.defaultOperTargetValue = defaultOperTargetValue;
	}
}
